package com.File_io_.stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author 宋鑫宇
 * @version 1.0
 * 初步体验Stream流
 */
public class Stream_ {
    public static void main(String[] args) {
        List<String> strings = new ArrayList<>();
        Collections.addAll(strings, "aaa", "bbb", "ccc", "ddd");
        System.out.println(strings);
        //从集合中找到a开头的数据放到新集合中
        List<String> list = new ArrayList<>();
        for (String s : strings) {
            if (s.startsWith("a")) {
                list.add(s);
            }
        }
        System.out.println(list);
        //使用Stream实现
        strings.stream().filter(s -> s.startsWith("a")).filter(s -> s.length() == 3).forEach(s -> System.out.println(s));


    }
}
